package com.cw.base.common.model.dto.base;

import java.io.Serializable;

import javax.validation.constraints.NotNull;

import lombok.Data;

/**
 * @author chenw
 * @version $$Id: BaseUserRequest.java, v 0.1 2018/9/19 下午2:41 chenw Exp $$
 */
@Data
public class BaseUserRequest implements Serializable {

    /** serialVersionUID */
    private static final long serialVersionUID = 782642745245832272L;

    /** 通行证ID */
    @NotNull(message = "通行证ID不能为空")
    private String authId;
    /** 签名-渠道端的用户认证ID */
    @NotNull(message = "签名不能为空")
    private String token;
    /**
     * 所属机构id
     */
    private String organId;
    /**
     * 所属机构名称
     */
    private String organName;

    /** 操作人id */
    private String operatorId;

    /** 操作人姓名 */
    private String operatorName;

    public static final class Builder {

        private BaseUserRequest instance = new BaseUserRequest();

        private Builder() {}

        /**
         * 获取实例
         *
         * @return {@link Builder}
         */
        public static Builder getInstance() {
            return new Builder();
        }

        /**
         * 获取实例
         *
         * @param instance 原实例
         * @return {@link Builder}
         */
        public static Builder getInstance(BaseUserRequest instance) {
            Builder builder = new Builder();
            builder.instance = instance;
            return builder;
        }

        /**
         * 添加参数
         *
         * @param authId 参数
         * @return {@link Builder}
         */
        public Builder addAuthId(String authId) {
            this.instance.setAuthId(authId);
            return this;
        }

        /**
         * 添加参数
         *
         * @param token 参数
         * @return {@link Builder}
         */
        public Builder addToken(String token) {
            this.instance.setToken(token);
            return this;
        }

        /**
         * 添加参数
         *
         * @param operatorId 参数
         * @return {@link Builder}
         */
        public Builder addOperatorId(String operatorId) {
            this.instance.setOperatorId(operatorId);
            return this;
        }

        /**
         * 添加参数
         *
         * @param operatorName 参数
         * @return {@link Builder}
         */
        public Builder addOperatorName(String operatorName) {
            this.instance.setOperatorName(operatorName);
            return this;
        }

        /**
         * 添加参数
         *
         * @param organId 参数
         * @return {@link Builder}
         */
        public Builder addOrganId(String organId) {
            this.instance.setOrganId(organId);
            return this;
        }

        /**
         * 添加参数
         *
         * @param organName 参数
         * @return {@link Builder}
         */
        public Builder addOrganName(String organName) {
            this.instance.setOrganName(organName);
            return this;
        }

        /**
         * 生成实例
         *
         * @return {@link BaseUserRequest}
         */
        public BaseUserRequest build() {
            return this.instance;
        }
    }

    /**
     * 相当于深拷贝出一个全新的{@link BaseUserRequest}对象
     *
     * @return 全新的 {@link BaseUserRequest}对象
     */
    public BaseUserRequest copy() {
        return BaseUserRequest.Builder.getInstance()
            .addOrganName(getOrganName())
            .addOrganId(getOrganId())
            .addOperatorName(getOperatorName())
            .addOperatorId(getOperatorId())
            .addToken(getToken())
            .addAuthId(getAuthId())
            .build();
    }
}
